package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RyStudent;
import com.ruoyi.system.service.IRyStudentService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * ry_studentController
 * 
 * @author ruoyi
 * @date 2022-07-21
 */
@Controller
@RequestMapping("/system/student")
public class RyStudentController extends BaseController
{
    private String prefix = "system/student";

    @Autowired
    private IRyStudentService ryStudentService;

    @RequiresPermissions("system:student:view")
    @GetMapping()
    public String student()
    {
        return prefix + "/student";
    }

    /**
     * 查询ry_student列表
     */
    @RequiresPermissions("system:student:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RyStudent ryStudent)
    {
        startPage();
        List<RyStudent> list = ryStudentService.selectRyStudentList(ryStudent);
        return getDataTable(list);
    }

    /**
     * 导出ry_student列表
     */
    @RequiresPermissions("system:student:export")
    @Log(title = "ry_student", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RyStudent ryStudent)
    {
        List<RyStudent> list = ryStudentService.selectRyStudentList(ryStudent);
        ExcelUtil<RyStudent> util = new ExcelUtil<RyStudent>(RyStudent.class);
        return util.exportExcel(list, "ry_student数据");
    }

    /**
     * 新增ry_student
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存ry_student
     */
    @RequiresPermissions("system:student:add")
    @Log(title = "ry_student", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RyStudent ryStudent)
    {
        return toAjax(ryStudentService.insertRyStudent(ryStudent));
    }

    /**
     * 修改ry_student
     */
    @RequiresPermissions("system:student:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        RyStudent ryStudent = ryStudentService.selectRyStudentById(id);
        mmap.put("ryStudent", ryStudent);
        return prefix + "/edit";
    }

    /**
     * 修改保存ry_student
     */
    @RequiresPermissions("system:student:edit")
    @Log(title = "ry_student", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RyStudent ryStudent)
    {
        return toAjax(ryStudentService.updateRyStudent(ryStudent));
    }

    /**
     * 删除ry_student
     */
    @RequiresPermissions("system:student:remove")
    @Log(title = "ry_student", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ryStudentService.deleteRyStudentByIds(ids));
    }
}
